package com.person.leetcode.editor.cn;

import java.util.HashMap;

/**
  * 961.在长度 2N 的数组中找出重复 N 次的元素
  * 2022-05-21 09:42:02
**/
public class Sequence_0961_NRepeatedElementInSize2nArray {
    public static void main(String[] args) {
        Solution solution = new Sequence_0961_NRepeatedElementInSize2nArray().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int repeatedNTimes(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int val = nums[i];
            if (map.containsKey(val)){
                int ans = map.get(val) + 1;
                if (ans == nums.length/2){
                    return val;
                }else{
                    map.put(val,ans);
                }
            }else{
                map.put(val,1);
            }
        }
        return 0;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
